package com.platform.modules.wallet.controller;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.platform.common.shiro.ShiroUtils;
import com.platform.common.utils.SnowflakeUtils;
import com.platform.common.version.ApiVersion;
import com.platform.common.version.VersionEnum;
import com.platform.common.web.domain.AjaxResult;
import com.platform.modules.wallet.domain.ChatTestMsg;
import com.platform.modules.wallet.service.ChatTestMsgService;
import com.platform.modules.wallet.service.WalletKPayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * 测试推送消息
 */
@RestController
@Slf4j
@RequestMapping("/chat")
public class TestMsgController {

    @Resource
    private ChatTestMsgService chatTestMsgService;
    @Resource
    private WalletKPayService walletKPayService;

    /**
     * 获取一条测试推送消息
     */
    @ApiVersion(VersionEnum.V1_0_0)
    @GetMapping("/getTestMsg")
    public AjaxResult getTestMsg() {

        ChatTestMsg oneMsg = chatTestMsgService.pull(ShiroUtils.getUserId());


        // false表示不跳过空值
        JSONObject json = JSONUtil.parseObj(oneMsg, false);

        JSONObject content = JSONUtil.parseObj(json.getJSONObject("content"));
        json.set("content", content);

        return AjaxResult.success(json);
    }

    @ApiVersion(VersionEnum.V1_0_0)
    @GetMapping("/testRegPay")
    public AjaxResult testRegPay(@RequestParam String phone,
                                 @RequestParam String name,
                                 @RequestParam String nick,
                                 @RequestParam String walletCode) {

        return AjaxResult.success(walletKPayService.withdraw(walletCode,
                new BigDecimal(1),
                String.valueOf(SnowflakeUtils.getNextId()),
                "123456"));
    }

}
